home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / hamradio / dspmorse.zip / SB.C < prev    next >
C/C++ Source or Header  |  1993-11-29  |  5KB  |  252 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. //    SB.C
  3. //        Sound Blaster CT-VOICE.DRV helper functions.
  4. /////////////////////////////////////////////////////////////////////////////
  5.  
  6. #include "sb.h"
  7.  
  8. static void far (*driver_mem)(void) = NULL;    // pointer to allocated CT-VOICE mem
  9. static void far (*driver)(void) = NULL;        // CT-VOICE entry point
  10.  
  11. /////////////////////////////////////////////////////////////////////////////
  12.  
  13. int sbInit(void)
  14. {
  15.     _BX = 3;
  16.     (*driver)();
  17.     return(_AX);
  18. }
  19.  
  20. /////////////////////////////////////////////////////////////////////////////
  21.  
  22. void sbOpen(void)
  23. {
  24.     FILE *f;
  25.     long length;
  26.     char *vp;
  27.     char var[129];
  28.     void far (*drv)(void);
  29.     int ver;
  30.                                         // Get a copy of the SOUND environ
  31.                                         // variable.  Turn it into the path
  32.                                         // for the CT-VOICE driver.
  33.     *(var) = 0;
  34.     vp = getenv("SOUND");
  35.     if (!vp)
  36.     {
  37.         puts("\nThe SOUND environment variable could not be found.");
  38.         exit(1);
  39.     }
  40.     strcpy(var,vp);
  41.     if(var[strlen(vp)-1] != '\\')
  42.     {
  43.         strcat(var,"\\");
  44.     }
  45.     strcat(var,"drv\\CT-VOICE.DRV");
  46.                                         // Open the file, chucking an error
  47.                                         // if it doesn't exist.
  48.     f = fopen(var,"rb");
  49.     if(!f)
  50.     {
  51.         printf("\nCould not open %s.\n", var);
  52.         exit(1);
  53.     }
  54.                                         // Get the driver length, allocate
  55.                                         // memory for it, create an entry
  56.                                         // point at offest 0x0000, load the
  57.                                         // file at SEG:0000, and close it.
  58.     length = filelength(fileno(f));
  59.     driver_mem = (void far *)malloc((int)length + 16);
  60.     driver = MK_FP(FP_SEG(driver_mem)+1,0);
  61.     fread(driver,1,(int)length,f);
  62.     fclose(f);
  63.                                         // Display CT-VOICE.DRV version.
  64.     _BX = 0;
  65.     (*driver)();
  66.     ver = _AX;
  67.     printf("\nCT-VOICE.DRV version %d.%d.", (ver>>8)&0xFF, ver&0xFF);
  68.                                         // Display CT-VOICE.DRV card type.
  69.     printf("\nSound Blaster card type: %d.", sbGetType());
  70.                                         // Get the BLASTER environment var.
  71.     var[0] = 0;
  72.     vp = getenv("BLASTER");
  73.     if (!vp)
  74.     {
  75.         puts("\nCould not find the BLASTER environment variable.");
  76.         exit(1);
  77.     }
  78.     strcpy(var, vp);
  79.                                         // Use the CT-VOICE.DRV function 0x1C
  80.                                         // to parse the BLASTER environment
  81.                                         // variable and set up the Sound
  82.                                         // Blaster card accordingly.
  83.                                         // Put a copy of "driver" in the
  84.                                         // stack segment, since the DS needs
  85.                                         // to change.
  86.     drv = driver;
  87.     asm {
  88.         push ds
  89.         push es
  90.         push di
  91.         push si
  92.     }
  93.     _ES = _DS = FP_SEG(var);
  94.     _DI = _SI = FP_OFF(var);
  95.     _BX = 0x1C;
  96.     (*drv)();
  97.     asm {
  98.         pop si
  99.         pop di
  100.         pop es
  101.         pop ds
  102.     }
  103.                                         // Make sure it worked.
  104.     if (_AX)
  105.     {
  106.         puts("\nThe BLASTER environment variable does not match your hardware.");
  107.         exit(1);
  108.     }
  109.                                         // Initialize the driver.
  110.     ver=sbInit();
  111.     if (ver)
  112.     {
  113.         printf("\nError %d initializing your Sound Blaster.\n", ver);
  114.         exit(1);
  115.     }
  116. }
  117.  
  118. /////////////////////////////////////////////////////////////////////////////
  119.  
  120. int sbSpeaker(int onoff)
  121. {
  122.     _BX = 4;
  123.     _AX = onoff & 0x0001;
  124.     (*driver)();
  125.     return(_AX);
  126. }
  127.  
  128. /////////////////////////////////////////////////////////////////////////////
  129.  
  130. void sbClose(void)
  131. {
  132.     _BX = 9;
  133.     (*driver)();
  134. }
  135.  
  136. /////////////////////////////////////////////////////////////////////////////
  137.  
  138. int sbSetStatWord(unsigned int *addr)
  139. {
  140.     _BX = 5;
  141.     _ES = FP_SEG(addr);
  142.     _DI = FP_OFF(addr);
  143.     (*driver)();
  144.     return(_AX);
  145. }
  146.  
  147. /////////////////////////////////////////////////////////////////////////////
  148.  
  149. int sbOutVoc(char *buffer)
  150. {
  151.     _BX = 6;
  152.     _ES = FP_SEG(buffer);
  153.     _DI = FP_OFF(buffer);
  154.     (*driver)();
  155.     return(_AX);
  156. }
  157.  
  158. /////////////////////////////////////////////////////////////////////////////
  159.  
  160. int sbInVoc(int sample_rate, char *buffer, long length)
  161. {
  162.     _DX = (unsigned)(length >> 16);
  163.     _CX = (unsigned)(length & 0x0000ffff);
  164.     _BX = 7;
  165.     _AX = sample_rate;
  166.     _ES = FP_SEG(buffer);
  167.     _DI = FP_OFF(buffer);
  168.     (*driver)();
  169.     return(_AX);
  170. }
  171.  
  172. /////////////////////////////////////////////////////////////////////////////
  173.  
  174. void sbStopVoc(void)
  175. {
  176.     _BX = 8;
  177.     (*driver)();
  178. }
  179.  
  180. /////////////////////////////////////////////////////////////////////////////
  181.  
  182. int sbPauseOut(void)
  183. {
  184.     _BX = 10;
  185.     (*driver)();
  186.     return _AX;
  187. }
  188.  
  189. /////////////////////////////////////////////////////////////////////////////
  190.  
  191. int sbResumeOut(void)
  192. {
  193.     _BX = 11;
  194.     (*driver)();
  195.     return _AX;
  196. }
  197.  
  198. /////////////////////////////////////////////////////////////////////////////
  199.  
  200. int sbSetRecSrc(int src)
  201. {
  202.     _BX = 17;
  203.     _AX = src;
  204.     (*driver)();
  205.     return _AX;
  206. }
  207.  
  208. /////////////////////////////////////////////////////////////////////////////
  209.  
  210. int sbSetRecMode(int mode)
  211. {
  212.     _BX = 16;
  213.     _AX = mode;
  214.     (*driver)();
  215.     return _AX;
  216. }
  217.  
  218. /////////////////////////////////////////////////////////////////////////////
  219.  
  220. int sbGetType(void)
  221. {
  222.     _BX = 20;
  223.     (*driver)();
  224.     return _AX;
  225. }
  226.  
  227. /////////////////////////////////////////////////////////////////////////////
  228.  
  229. char *sbLoadVoc(char *name)
  230. {
  231.     FILE *f;
  232.     char *buf;
  233.     long length;
  234.  
  235.     f = fopen(name,"rb");
  236.     if(!f)
  237.         return NULL;
  238.  
  239.     length = filelength(fileno(f)) - 0x1a;
  240.  
  241.     buf = (char *)malloc((int)length);
  242.     fseek(f,0x1a,SEEK_SET);
  243.     fread(buf,1,length,f);
  244.  
  245.     fclose(f);
  246.     return buf;
  247. }
  248.  
  249. /////////////////////////////////////////////////////////////////////////////
  250. //    end of SB.C
  251. /////////////////////////////////////////////////////////////////////////////
  252.